********************************************************************************
* ELECTORAL REPERCUSSIONS OF A PANDEMIC:  EVIDENCE FROM THE 2009 H1N1 OUTBREAK *
********************************************************************************

// NOVEMBER 2, 2021

// THIS FILE REPLICATES TABLES C1 AND C4-C8 IN APPENDIX C OF "ELECTORAL 
// REPERCUSSIONS OF A PANDEMIC: EVIDENCE FROM THE 2009 H1N1 OUTBREAK" BY
// EMILIO GUTIÉRREZ, JAAKKO MERILÄINEN, AND ADRIÁN RUBLI

global data "XXX" // Insert data directory here
global output "XXX" // Insert output directory here

* Open data

use "$data/GMR_data_main.dta", clear

egen munid=group(estado municipio) // Generate an identifier for municipalities
gen year2=year*year

********************************************************************************

* Table C1

est clear

preserve

keep if year==2006 | year==2009
gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari if year==2006 | year==2009, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

keep if year==2006 | year==2009
gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z if year==2006 | year==2009, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari, absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore


preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z, absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari, absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z, absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore


esttab est*  using "$output/tableC1.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "1997-2012", pattern(1 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear linear quadratic, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE" "Linear time trend" "Quadratic time trend") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{9}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})

********************************************************************************

* Table C4

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

esttab est*  using "$output/tableC4.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear linear quadratic, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE" "Linear time trend" "Quadratic time trend") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{7}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})

********************************************************************************

* Table C5

xtile pctiles = change_ari, nq(100)
xtile pctiles2 = change_ari_z, nq(100)

preserve

keep if year==2006 | year==2009
keep if  pctiles<=95 & pctiles>=5
gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

keep if year==2006 | year==2009
keep if  pctiles2<=95 & pctiles2>=5
gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=95 & pctiles>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=95 & pctiles2>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos] if pctiles2<=95, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=95 & pctiles>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore


preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=95 & pctiles2>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=95 & pctiles>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=95 & pctiles2>=5
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore

esttab est*  using "$output/tableC5.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "1997-2012", pattern(1 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear linear quadratic, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE" "Linear time trend" "Quadratic time trend") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{9}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})

********************************************************************************

* Table C6

preserve

keep if year==2006 | year==2009
keep if  pctiles<=99 & pctiles>=1
gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

est clear

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

keep if year==2006 | year==2009
keep if  pctiles2<=99 & pctiles2>=1
gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=99 & pctiles>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=99 & pctiles2>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos] if pctiles2<=99, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=99 & pctiles>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore


preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=99 & pctiles2>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
keep if  pctiles<=99 & pctiles>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
keep if  pctiles2<=99 & pctiles2>=1
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore

esttab est*  using "$output/tableC6.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "1997-2012", pattern(1 0 1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear linear quadratic, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE" "Linear time trend" "Quadratic time trend") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{9}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})

********************************************************************************

* Table C7

est clear

preserve

keep if year==2006 | year==2009
gen a=1 if excess_deaths!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

eststo: reghdfe PAN_voteshare 1.post##c.excess_deaths [aw = total_votos] if year==2006 | year==2009, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "
restore

preserve

gen a=1 if excess_deaths!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.excess_deaths [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic " "

restore

preserve

gen a=1 if excess_deaths!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.excess_deaths [aw = total_votos], absorb(id i.munid#i.year i.id#c.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear "\checkmark"
estadd local quadratic " "

restore

preserve

gen a=1 if excess_deaths!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==6

eststo: reghdfe PAN_voteshare 1.post##c.excess_deaths [aw = total_votos], absorb(id i.munid#i.year i.id#c.year i.id#c.year2) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/6
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
estadd local linear " "
estadd local quadratic "\checkmark"

restore


esttab est*  using "$output/tableC7.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "1997-2012", pattern(1 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear linear quadratic, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE" "Linear time trend" "Quadratic time trend") ///
	fmt(0 0 0)) keep(1.post#c.excess_deaths) ///
	coeflabels(1.post#c.excess_deaths "1[Year $\geq$ 2009] $\times$ Excess deaths") ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{6}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})
	
********************************************************************************
	
* Table C8

preserve

keep if year==2006 | year==2009
gen a=1 if change_ari!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

est clear

eststo: reghdfe turnout 1.post##c.change_ari [aw = total_votos] if year==2006 | year==2009, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
restore

preserve

keep if year==2006 | year==2009
gen a=1 if change_ari_z!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==2

eststo: reghdfe turnout 1.post##c.change_ari_z [aw = total_votos] if year==2006 | year==2009, absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/2
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"
restore

preserve

gen a=1 if change_ari!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==3

eststo: reghdfe turnout 1.post##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/3
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

preserve

gen a=1 if change_ari_z!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==3

eststo: reghdfe turnout 1.post##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
estadd scalar N1 = e(N)
estadd scalar N2 = e(N)/3
estadd scalar N3 = e(N_clust)
estadd local district "\checkmark"
estadd local stateyear "\checkmark"

restore

esttab est*  using "$output/tableC8.tex", replace noomitted nobaselevels booktabs  mlabels(none) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	mgroups("2006-2009" "2006-2012", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	b(%9.3f) se(%9.3f) stats(N1 N2 N3 district stateyear, labels("Number of observations" "Number of sections" "Number of clusters" "Section FE" "Municipality-year FE") ///
	fmt(0 0 0)) keep(1.post#c.change_ari 1.post#c.change_ari_z) ///
	coeflabels(1.post#c.change_ari "1[Year $\geq$ 2009] $\times$ Excess ARI cases (1000s)" ///
	1.post#c.change_ari_z "1[Year $\geq$ 2009] $\times$ Excess ARI cases (z-score)") ///
	order(1.post#c.change_ari 1.post#c.change_ari_z) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
	postfoot(\bottomrule \end{tabular})
